#ifndef OPERATIONFUN_H
#define OPERATIONFUN_H
#include "sndarecord.pb.h"
class operation_KeyPrimer
{
    public:
        bool operator()(const class keyprimer * m1,
                const class keyprimer * m2) const
        {
            
            if((m1->host() != "") && (m2->host() == ""))
            {
                return false;
            }
            else if((m1->host() == "") && (m2->host() != ""))
            {
                return true;
            }
            if(m1->host() < m2->host())
            {
                return true;
            }
            else if(m1->host() > m2->host())
            {
                return false;
            }

            if(m1->diskid() < m2->diskid())
            {
                return true;
            }
            else if(m1->diskid() > m2->diskid())
            {
                return false;
            }

            if(m1->chunk() < m2->chunk())
            {
                return true;
            }
            else if(m1->chunk() > m2->chunk())
            {
                return false;
            }

            if(m1->id() < m2->id())
            {
                return true;
            }
            else if(m1->id() > m2->id())
            {
                return false;
            }
            
            return false;
        }
        
        bool less(const class keyprimer * m1, const class keyprimer * m2) const
        {
            
            if((m1->host() != "") && (m2->host() == ""))
            {
                return true;
            }
            else if((m1->host() == "") && (m2->host() != ""))
            {
                return false;
            }

            if(m1->host() < m2->host())
            {
                return false;
            }
            else if(m1->host() > m2->host())
            {
                return true;
            }

            if(m1->diskid() < m2->diskid())
            {
                return false;
            }
            else if(m1->diskid() > m2->diskid())
            {
                return true;
            }

            if(m1->chunk() < m2->chunk())
            {
                return false;
            }
            else if(m1->chunk() > m2->chunk())
            {
                return true;
            }

            if(m1->id() < m2->id())
            {
                return false;
            }
            else if(m1->id() > m2->id())
            {
                return true;
            }
            return false;
        }
};

class operation_keybaserecord_byKeyPrimer
{
    public:
        
        bool operator()(const class keybaserecord * m1,
                const class keybaserecord * m2) const
        {
            operation_KeyPrimer oper;
            if(oper(&(m1->disk1()), &(m2->disk1()))){
            return true;
        }
        else if ( oper.less(&(m1->disk1()) , &(m2->disk1())))
        {   
            return false;
        }   

            if(oper(&(m1->disk2()), &(m2->disk2()))){
            return true;
        }
        else if ( oper.less(&(m1->disk2()) , &(m2->disk2())))
        {   
            return false;
        }   

            if(oper(&(m1->disk3()), &(m2->disk3()))){
            return true;
        }
        else if ( oper.less(&(m1->disk3()) , &(m2->disk3())))
        {   
            return false;
        }   
            return false;
        }
};

class operation_keybaserecord_bykey
{
    public:
        
        bool operator()(const class keybaserecord * m1,
                const class keybaserecord * m2) const
        {
            if(m1->bucket() < m2->bucket())
            {
                return true;
            }
            else if(m1->bucket() > m2->bucket())
            {
                return false;
            }

            if(m1->indexkey() < m2->indexkey())
            {
                return true;
            }
            else if(m1->indexkey() > m2->indexkey())
            {
                return false;
            }
            if(m1->user_time_stamp() < m2->user_time_stamp())
            {
                return true;
            }
            else if(m1->user_time_stamp() > m2->user_time_stamp())
            {
                return false;
            }

            if(m1->internal_time_stamp() < m2->internal_time_stamp())
            {
                return true;
            }
            else if(m1->internal_time_stamp() > m2->internal_time_stamp())
            {
                return false;
            }

            operation_keybaserecord_byKeyPrimer oper;
            return oper(m1, m2);
            
        }
};

class euqalrecord
{
    public:
        bool euqal(const class keybaserecord * m1,
                const class keybaserecord * m2) const
        {
            
            if((m1->bucket() == m2->bucket())
                    && (m1->indexkey() == m2->indexkey()))
            {
                return true;
            }
            return false;
        }
        
};

class DelMarkereuqal
{
    public:
        bool euqal(const class keybaserecord * m1) const
        {
            
            if(m1->del_mark() == true)
            {
                return true;
            }
            return false;
        }
        
};

#endif
